﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace SkinableFormsLib
{
	public class LWLabelScrollable : LWLabel
	{
		internal string _text = String.Empty;
		public new string Text
		{
			get
			{
				return _text;
			}
			set
			{
				_text = value;
				//base.Text = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="characterCount">positive for RTL scroll / negative for LTR scroll</param>
		/// <returns></returns>
		private string ScrollText(int characterCount)
		{
			if (_text.Length == 0)
				return _text;
			int pos = (_text.Length + characterCount) % _text.Length;


			string ret = _text.Substring(pos, _text.Length - pos) + " " + _text.Substring(0, pos);
			return ret;
		}

		private int _lwScrollShift = 0;
		public int LWScrollShift
		{
			get
			{
				return _lwScrollShift;
			}
			set
			{
				_lwScrollShift = value;
			}
		}






		protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
		{
			base.Text = ScrollText(_lwScrollShift);
			base.OnPaint(e);
		}



		/*
		 private Timer _timer;
		 private bool _lwAutoScroll;


		 private RightToLeft _lwAutoScrollDirection = RightToLeft.Yes;
		 [Browsable(false)]
		 public RightToLeft LWAutoScrollDirection
		 {
			 get { return _lwAutoScrollDirection; }
			 set { _lwAutoScrollDirection = value; }
		 }
		 
		 [Browsable(false)]
		 public bool LWAutoScroll
		 {
			 get { return _lwAutoScroll; }
			 set
			 {
				 if (value)
				 {
					 if (_timer == null)
					 {
						 _timer = new Timer();
						 _timer.Tick += new EventHandler(_timer_Tick);
					 }
					 if (_lwAutoScrollInterval >= 0)
						 _timer.Interval = _lwAutoScrollInterval;
					 _timer.Enabled = true;
				 }
				 else
				 {
					 _timer.Enabled = false;
				 }
				 _lwAutoScroll = value;
			 }
		 }

		 void _timer_Tick(object sender, EventArgs e)
		 {
			 if (_lwAutoScrollDirection == RightToLeft.No)
				 LWScrollShift++;
			 else if (_lwAutoScrollDirection == RightToLeft.Yes)
				 LWScrollShift--;
			 LWScrollShift %= Text.Length;
		 }

		 private int _lwAutoScrollInterval = 300;
		 [Browsable(false)]
		 public int LWAutoScrollInterval
		 {
			 get { return _lwAutoScrollInterval; }
			 set
			 {
				 _lwAutoScrollInterval = value;
			 }
		 }
			*/



	}
}
